<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	String type = (String)request.getAttribute("type");
	String otype = (String)request.getAttribute("otype");
	String organizationId = (String)request.getAttribute("organizationId");
	int ptype = 0;
	if(!("".equals(otype))) {
		ptype = Integer.parseInt(otype)+1;
	}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>新增机构</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<script type="text/javascript" src="<%=basePath%>ckeditor/ckeditor.js"></script>
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<jsp:include page="/page/head.jsp"></jsp:include>
<script type="text/javascript">
		//打开页面判断操作类型是否为edit，为edit则在加载事件根据url参数中传递过来的organizationId查找出当前用户的信息作出修改
		var uId = "<%=organizationId%>";
		var otype = "<%=otype%>";
		$(document).ready(function(){
		});	
	
		//保存信息
		function save(){
			var name = escape(escape($('#name').val()));    //获取name值
			var areaNode = escape(escape($('#areaNode').combobox('getValue')));
			var areaName = escape(escape($('#areaNode').combobox('getText')));
			var tel = escape(escape($('#tel').val()));    		//获取tel值
			var address = escape(escape($('#address').val()));	//获取sscore值
			var busLine = escape(escape($('#busLine').val()));   //获取busLine值
			var parentId = escape(escape($('#parent').combobox('getValue')));    //获取parent值
			var legal = escape(escape($('#legal').val()));  //获取legal值
			
			if($('#fm').form('validate')){
				//做操作类型判断
				var type = "<%=type%>";
				var url = "";
				if(type == "add"){
					//add处理路径
					url = path +"/organization/save.do?otype="+otype+"&name="+name+"&areaNode="+areaNode+"&areaName="+areaName+"&tel="+tel+"&address="+address+"&busLine="+busLine+"&parentId="+parentId+"&legal="+legal;
				}else{
					//update处理
					url = path +"/organization/update.do?otype="+otype+"&name="+name+"&areaNode="+areaNode+"&areaName="+areaName+"&tel="+tel+"&address="+address+"&busLine="+busLine+"&parentId="+parentId+"&legal="+legal;
					url += "&organizationId="+uId;
				}
				
				$.ajax({
					  url:url,
					  success: function() {
						  window.location = path+"/organization/organizationMgr.do?otype="+otype;
					  }
					});
			}
		}
		
		//撤销回退
		function callback(){
			window.location = path+"/organization/organizationMgr.do?otype="+otype;
		}
		
		function selectUser(){
			var w =(screen.width-650)/2;
			var h = (screen.height-500)/2;
			var ret = window.showModalDialog(path+"/page/common/select-user.jsp",null,"dialogWidth:650px;dialogHeight:500px;dialogTop:"+h+"px;dialogLeft:"+w+"px;help:no;status:no;center:yes");
			if(ret != null){
				$('#legal').attr('value',ret[0]);
				$('#legalName').attr('value',ret[1]);
			}
		}
	</script>
	<script type="text/javascript">
		$.extend($.fn.validatebox.defaults.rules, { 
			tel:{                                      //手机号码或座机
		    	validator: function (value) {
		            return /(^(\d{3,4})?[-]?\d{7,8})$|(^1[3|4|5|8][0-9]\d{8}$)/.test(value) ;
		        },
		        message: '输入正确的电话号码!'
			}
		});
	</script>
</head>

<body>
	<div class="right">
		<h1>
			<b>
			${otype=='2'?type=='add'?'新增推广站':'编辑推广站':otype=='3'?type=='add'?'新增推广中心':'编辑推广中心':otype=='4'?type=='add'?'新增运营中心':'编辑运营中心':type=='add'?'新增机构':'编辑机构' }
			</b><span><img
				src="<%=basePath%>images/right_h1bg2.jpg" width="3" height="29" /></span>
		</h1>
		<div class="ri_main">
			<form id="form">
				<table width="100%" border="0" cellspacing="1" cellpadding="8"
					style="background: #d9d9d9;">
					<tr>
						<td width="15%" align="right" bgcolor="#FFFFFF">名称</td>
						<td width="35%" bgcolor="#FFFFFF" align="left"><label
							for="textfield"></label> <input id="name" name="name"
							class="easyui-validatebox" required="true" style="width: 150px;"
							value="${organization != null?organization.name:''}">
		    			</td>
		    			<td align="right" bgcolor="#FFFFFF">乘车路线</td>
						<td bgcolor="#FFFFFF" align="left" width="35%"><input
							id="busLine" name="busLine" class="easyui-validatebox"
							required="true" style="width: 150px;" value="${organization != null?organization.busLine:''}"></td>
		    			
					</tr>
					
					<tr>
						<td width="15%" align="right" bgcolor="#FFFFFF">电话</td>
						<td bgcolor="#FFFFFF"  align="left" width="35%"><label
							for="textfield"></label> 
						<input validType="tel"
							id="tel" name="tel" class="easyui-validatebox" required="true"
							style="width: 150px;" value="${organization != null?organization.tel:''}"></td>
						<td align="right" bgcolor="#FFFFFF">所属区域</td>
						<td bgcolor="#FFFFFF" align="left">
							<input class="easyui-combobox" 
								name="areaNode"
								id="areaNode"
								url="${pageContext.request.contextPath}/intra/city/listToCombobox.do" 
								valueField="areaId" 
								textField="areaName" 
								panelHeight="auto" 
								value="${organization != null?organization.areaNode:''}"
								required="true" />
						</td>
						
					</tr>
					
					<tr>
						<td align="right" bgcolor="#FFFFFF">地址</td>
						<td bgcolor="#FFFFFF" align="left"><input validType="address"
							id="address" name="address" class="easyui-validatebox"
							required="true" style="width: 150px;" value="${organization != null?organization.address:''}"></td>
						<td align="right" bgcolor="#FFFFFF">所属机构</td>
						<td bgcolor="#FFFFFF" align="left" >
						<input  
								class="easyui-combobox" <c:if test="${otype=='5'}">disabled="disabled"</c:if>  name="language" name="parent" id="parent"
								url="organization/listParent.do?type=<%=ptype%>" valueField="id"
								textField="name" panelHeight="auto" 
								value="${organization != null?organization.parent.id:''}" 
								text="${organization != null?organization.parent.name:''}"  />
						</td>
					</tr>
					
					<tr>
						<td align="right" bgcolor="#FFFFFF">负责人</td>
						<td bgcolor="#FFFFFF" align="left" width="35%" colspan="3">
						<input disabled="disabled"
							class="easyui-validatebox" required="true" style="width: 150px;"
							name="legalName" id="legalName" value="${organization != null?organization.legal.truename:''}">
						<input type="hidden" name="legal" id="legal"/>
						<input type="button" value="选择" onclick="selectUser()">
						</td>
					</tr>
					<tr>
						<td bgcolor="#FFFFFF" colspan="4" align="center"><a
							href="javascript:void(0);" class="easyui-linkbutton"
							iconCls="icon-ok" onclick="save()">保存</a> <a
							href="javascript:void(0);" class="easyui-linkbutton"
							iconCls="icon-cancel" onclick="callback()">取消</a>
						</td>
					</tr>
					
				</table>
			</form>
		</div>
	</div>
</body>
</html>
